package cn.pet_know.feigns;

import cn.pet_know.common.constants.DelFlag;
import cn.pet_know.common.entity.dto.UserDTO;
import cn.pet_know.common.entity.vo.UserVO;
import cn.pet_know.common.feigns.UserFeign;
import cn.pet_know.common.result.R;
import cn.pet_know.common.utils.ConverterUtils;
import cn.pet_know.entity.User;
import cn.pet_know.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserFeignImpl implements UserFeign {

    @Resource
    private UserService userService;

    @Override
    public R<UserVO> findUser(UserDTO userDTO) {
        cn.pet_know.entity.dto.UserDTO param = ConverterUtils.copyR(userDTO, new cn.pet_know.entity.dto.UserDTO());
        cn.pet_know.entity.vo.UserVO user = userService.findUser(param);
        UserVO userVO = ConverterUtils.copyR(user, new UserVO());
        return R.ok(userVO);
    }

    @Override
    public R<List<UserVO>> findUserList(List<Long> userIds) {
        List<User> list = userService.list(new LambdaQueryWrapper<User>().in(User::getUserId, userIds).eq(User::getDeleted, DelFlag.EXISTS));
        List<UserVO> userVOS = ConverterUtils.listCopyR(list, UserVO.class);
        return R.ok(userVOS);
    }
}
